﻿//***************************************************************************//
//                                                                           //
//Author:       Kris Henry                                                   //
//Class Name:   OptionsState.cs                                              //
//Pupose:       Handle the drawing and input for the setting of the          //
//              ingame options                                               //
//Date :        December 2012                                                //
//                                                                           //
//***************************************************************************//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;


namespace Indie_Game_Contest
{
    class PauseState : IGameState
    {
        //////////////////////////////////////////////////////////////////////////
        // Data Members
        static PauseState instance = new PauseState();
        TextureManager tm = TextureManager.Instance;

        int fontID;
        int bgID;

        string szPaused = "PAUSED";
        string szContinue = "Continue";
        string szQuit = "Quit";
        Color[] colors = new Color[2];

        int selected = 0;

        //////////////////////////////////////////////////////////////////////////
        // Methods
        override public void Update(float dt)
        {
            for (int i = 0; i < 2; ++i)
            {
                colors[i] = Color.CornflowerBlue;
            }

            colors[selected] = Color.Yellow;
        }
        override public bool Input()
        {
            if (CInput.Instance.GamePadButtonPressed(Buttons.B))
                Game1.Instance.RemoveState();

            if (CInput.Instance.KeyPressed(Keys.Enter) || CInput.Instance.GamePadButtonPressed(Buttons.A))
            {
                switch (selected)
                {
                    case 0:
                        Game1.Instance.RemoveState();
                        break;
                    case 1:
                        Game1.Instance.RemoveState();
                        Game1.Instance.AddState(MainMenuSate.Instance);
                        Game1.Instance.RemoveState(GameplayState.Instance);
                        break;
                }
            }
            if (CInput.Instance.KeyPressed(Keys.Up))
            {
                --selected;

                if (selected < 0) selected = 1;
            }
            if (CInput.Instance.KeyPressed(Keys.Down))
            {
                ++selected;

                if (selected > 1) selected = 0;
            }

                return true;
        }
        override public void Render()
        {
            WorldData.spriteBatch.Draw(tm.GetTexture(bgID), new Rectangle(0, 0, WorldData.WindowWidth, WorldData.WindowHeight), Color.FromNonPremultiplied(255, 255, 255, 180));

            WorldData.spriteBatch.DrawString(tm.GetSpriteFont(fontID), szPaused,
                new Vector2(WorldData.WindowWidth / 2 - szPaused.Length * 10, WorldData.WindowHeight / 4 - 24), Color.CornflowerBlue);
            WorldData.spriteBatch.DrawString(tm.GetSpriteFont(fontID), szContinue,
                new Vector2(WorldData.WindowWidth / 2 - szContinue.Length * 10, WorldData.WindowHeight / 2 - 24), colors[0]);
            WorldData.spriteBatch.DrawString(tm.GetSpriteFont(fontID), szQuit,
                new Vector2(WorldData.WindowWidth / 2 - szQuit.Length * 10, WorldData.WindowHeight / 2 + 24),colors[1]);
        }
        override public void Enter()
        {
            CInput.Instance.Clear();

            colors[0] = Color.CornflowerBlue;
            colors[1] = Color.CornflowerBlue;
            selected = 0;
        }
        override public void Exit()
        {

        }

        //////////////////////////////////////////////////////////////////////////
        // Properties
        public int BgID
        {
            get { return bgID; }
            set { bgID = value; }
        }
        public static Indie_Game_Contest.PauseState Instance
        {
            get { return instance; }
        }
        public int FontID
        {
            get { return fontID; }
            set { fontID = value; }
        }
    }
}
